package com.google.gwt.livinglife.client.widgets;

import java.util.Date;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.livinglife.client.data.BasicPostData;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

public abstract class BasicEntryForm extends Composite{
	protected DockPanel main_panel = new DockPanel();
	private TextArea text_area = new TextArea();
	private TextBox url_box = new TextBox();
	private Label url_box_label = new Label("Add Image Url");
	private Button submit_button = new Button("Submit");
	ClickHandler submit_handler;
	
	public BasicEntryForm () {
		main_panel.setWidth("500px");
		main_panel.add(text_area, DockPanel.NORTH);
		text_area.setWidth("500px");
		main_panel.add(url_box, DockPanel.EAST);
		url_box.setWidth("300px");
		main_panel.add(url_box_label, DockPanel.WEST);
		main_panel.add(submit_button, DockPanel.SOUTH);
	  main_panel.setHorizontalAlignment(DockPanel.ALIGN_RIGHT);
	  submit_button.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				handleSubmit();
			}
	  	
	  });
	  initWidget(main_panel);
	}
		
	public void onModuleLoad() {
	}
	
	public abstract void handleSubmit();
	
	protected Boolean FillBasicPost(BasicPostData post_data) {
		if (post_data != null) {
			post_data.setEmbeded_image(url_box.getText());
			post_data.setPost_text(text_area.getText());
			post_data.setCreation_date(new Date());
		}
		return false;
	}
	
}
